Spatial median filter

ABSTRACT

A spatial median filter determines a median of a plurality of values by dividing the plurality of values into a plurality of groups of values. The values in each of the groups are sorted to determine its median. Then, the medians of the plurality of groups are fully sorted. Certain of the sorted values are eliminated from prescribed ones of the groups in accordance with prescribed criteria based on the number of values in the group and the median value of the group values. The remaining values are sorted to determine the median of the plurality of values.

RELATED APPLICATIONS

[0001] This application claims the priority of the corresponding provisional application, Ser. No. 60/192,294, filed Mar. 27, 2000. U.S. patent application Ser. No. (H. Jiang Case 10-20-9) was filed concurrently herewith.

TECHNICAL FIELD

[0002] This invention relates to filters and, more particularly, to determining the median of a plurality of values.

BACKGROUND OF THE INVENTION

[0003] A standard prior known approach in finding a median of N values is to fully sort the sequence of N values by arranging the N values in the sequence in either ascending or descending order, e.g., 4, 10, 20, . . . or . . . , 20, 10, 4, respectively, and then picking the middle value of the sorted sequence of N values. The optimal number of comparisons needed to sort N values is in the order of K*N*log(N), where K is some constant independent of N. This process of finding a median is not optimal, because the sorting is more than what is needed to locate the median. Sorting arranges all values in an ascending or a descending order. It produces the location of every value in the sequence, not only the median. In locating a median, only the median itself is of interest, it is not necessary to know the order of other values in the sequence. Therefore, using a full sorting process to locate the median is not optimal, and it requires making significantly more comparisons than are actually necessary.

SUMMARY OF THE INVENTION

[0004] The problems and limitations of prior spatial median filters is overcome in determining a median of a plurality of values, in accordance with the invention, by dividing the plurality of values into a plurality of groups of values. The values in each of the groups are sorted to determine its median. Then, the medians of the plurality of groups are fully sorted. Certain sorted values are eliminated from prescribed ones of the groups in accordance with prescribed criteria based on the number of values in the group and the median value of the group values. The remaining values are sorted to determine the median of the plurality of values.

[0005] A technical advantage of the invention is that fewer comparisons are required to determine the median of a plurality of values than in prior known arrangements. Consequently, this results in a significantly simpler implementation of a spatial median filter including an embodiment of the invention.

[0006] Another technical advantage of the invention is that in the process of determining the median values that are less than or equal and values that are greater than or equal to the median are also identified without any additional processing.

BRIEF DESCRIPTION OF THE DRAWING

[0007]FIG. 1 shows, in simplified form details of a nine-value, i.e., point, spatial median filter including an embodiment of the invention; and

[0008]FIG. 2 shows, in simplified form, details of a so-called pseudo nine-value spatial median filter including an embodiment of the invention.

DETAILED DESCRIPTION OF THE INVENTION

[0009] A. Theoretical Discussion

[0010] By employing an embodiment of the current invention, finding the median of N values is more efficient than the prior known process of full sorting. Finding the median of N values is divided into a group of problems of finding the median of M values, where M is significantly smaller than N. The total number of comparisons required to solve the group of problems is smaller than that required to sort the original N values.

[0011] More specifically, to find the median of N values, we divide the N values, in this example, into three groups, namely, G₁, G₂ and G₃. Assume group G₁ has N₁ values, group G₂ has N₂ values and group G₃ has N₃ values. Therefore, the three groups contain all N values, namely, N=N₁+N₂+N₃. Now assume that a median has been determined for each of the groups G₁, G₂ and G₃, and have been labeled as A₁, A₂ and A₃, respectively. A₁ is the median of group G₁, A₂ is the median of group G₂ and A3 is the median of group G₃.

[0012] Furthermore, it is assumed that all values have been determined in group G₁ that are less than or equal to median A₁. These values are designated as being in sub-group G₁₁. Similarly, all values that are greater than or equal to median A₁ in group G₁ are designated as being in sub-group G₁₂. All values in group G₂ that are less than or equal to median A₂ are designated as being in sub-group G₂₁. Similarly, all values in group G₂ that are greater than or equal to median A₂ are designated as being in sub-group G₂₂. All values in group G₃ that are less than or equal to median A₃ are designated as being in sub-group G₃₁. Similarly, all values in group G₃ that are greater than or equal to median A₃ are designated as being in sub-group G₃₂.

[0013] How the median A₁ and the first set of sub-groups including G₁₁ and G₁₂ of group G₁ are determined is not being specified at this moment. It is sufficient to say that they may be found by using the current process: further dividing group G₁ into a second set of three sub-groups, and applying the current process recursively. When eventually, a subgroup in the second set contains 9 or fewer values, the median of the particular sub-group can be found by using the median determining process of the 9-value, i.e., point, spatial median filter to be described in more detail below in relationship to the 9-value spatial median filter implementation. This process also applies to the remaining groups which, in this example, are groups G₂ and G₃. Medians A₂ and A₃ and the corresponding subgroups G₂₁, and G₂₂, and G₃₁ and G₃₂ of groups G₂ and G₃, respectively, are found in the same manner as median A₁ and sub-groups G₁₁ and G₁₂ of group G₁.

[0014] It is noted that the current process, in addition to determining the median of each group of values, also yields a sub-group including all values that are less than or equal to the median of the group and a sub-group including all values that are greater than or equal to the median of the group. This is realized without any additional processing.

[0015] For now, it is assumed that the three medians and six sub-groups have been determined, namely, median A₁, and sub-groups including G₁₁ and G₁₂ of group G₁, median A₂, and sub-groups G₂₁ and G₂₂ of group G₂, and median A₃, and sub-groups G₃₁, and G₃₂ of group G₃. Then, the three medians A₁, A₂ and A₃ are fully sorted. Without loss of generality, we can assume A₁≦A₂≦A₃. If they are not, the smallest value of A₁, A₂ and A₃ is re-labeled to be A₁, and its associated group as G₁, and the associated sub-groups as G₁₁, and G₁₂ etc.

[0016] At this stage, some values can be eliminated from the N values. That is, the median of the N values is guaranteed to be among the surviving values. Specifically, median A₁ and all values in sub-group G₁₁ can be eliminated. Additionally, median A₃ and all values in sub-group G₃₂ can also be eliminated. Let M₁=floor(N₁/2), i.e., the largest integer that is less than or equal to N₁/2. Note M₁=(N₁−1)/2, if N₁ is odd. M₁ includes all the values in sub-group G₁₁ because they are less than or equal to A₁. Similarly, let M₃=floor(N₃/2), i.e., the smallest integer that is greater than or equal to N₃/2. M₃ includes all values in sub-group G₃₂ because they are greater than or equal to A₃. The total number of values eliminated is therefore equal to M₁+M₃+2. After the elimination of these values, the surviving values from the original N values are:

[0017] a) all values in sub-group G₁₂ from group G₁ that are greater than or equal to A₁, excluding A₁, there are M₁−1 of them;

[0018] b) all values in group G₂ (N₂ of them); and

[0019] c) all values in sub-group G₃₁ from group G₃ that are less than or equal to A₃, excluding A₃, there are M₃−1 of them.

[0020] Therefore, the total number of surviving values is P=N−floor(N₁/2)−floor(N₃/2)−2. Now the remaining task is to find the median of the remaining P=(N−floor(N₁/2)−floor(N₃/2)−2) values. Thus, the original problem of finding the median of N values is reduced to the following:

[0021] 1) find three medians of the three groups of size N₁, N₂, and N₃, and obtain sub-groups G₁₁, G₁₂, G₂₁, G₂₂, G₃₁, and G₃₂;

[0022] 2) find the median of the three medians in 1) above;

[0023] 3) find the median of the remaining P=(N−floor(N₁/2)−floor(N₃/2)−2) values, and find the two sub-groups, a first sub-group including all values that are less than or equal to the median of the P values and a second sub-group including all values that are greater than or equal to the median of the P values.

[0024] This process can be applied recursively to finding the medians in the steps 1) and 3) above. For example, the problem of finding the median A₁ of group G₁ can be further divided into the above three steps. The recursion stops when the size of median filter is small, for example, 9. At that point, the process of finding the median in a 9-value spatial median filter can be used. If one starts with N<9, the above process still can be applied. The size is recursively reduced. The recursion stops when the size becomes three (3). Then, the median of 3-points can be found by sorting the three values. The optimal 3-value spatial median filter is the same as the full sort of the 3 values.

[0025] B. Preferred Embodiments

[0026]FIG. 1 shows, in simplified form, details of a so-called 9-value spatial median filter that is advantageously used in practicing the invention. The spatial median filter can be advantageously employed to measure the overall effect of all values that make up an object. Additionally, since each individual value may be prone to random noise, use of spatial median filter can also reduce the effects of the noise.

[0027] Referring to FIG. 1, it is seen that the 9-points, i.e., values, are arranged into three groups of three values each, namely, a first group including values a, b and c, a second group including values d, e and f, and a third group including values g, h and j. The first group is supplied to sorter 101, the second group to sorter 102 and the third group to sorter 103. Sorters 101, 102 and 103 each perform a complete sort of their respective supplied groups, i.e., arrange the supplied values in either ascending or descending order. In the spatial median filter shown in FIG. 1, it is assumed that the values are arranged in ascending order. That is, a₃≧a₂≧a₁ and so on for the other values. Note that a sorter of three values requires three comparisons. Thus, the three sorters 101, 102 and 103 perform nine comparisons. The median of each group is determined to be the middle value in the sorted group. The three medians from sorters 101, 102 and 103, in this example, are a₂, b₂ and c₂, respectively, and are supplied to sorter 104. In turn, sorter 104 sorts the three medians a₂, b₂ and c₂. This requires another three comparisons. After sorting, the three medians a₂, b₂ and c₂, are assumed to be arranged in ascending order and are designated λ, β and γ, respectively, where λ≦β≦γ. Now the nine values of the spatial median filter are reduced to five values by removing four values. The remaining five values include the median of the nine values. This reduction is realized by first identifying the group of three values whose median is λ. These values are labeled in ascending order as d₁≦d₂≦d₃. It is noted that these three values had been sorted in the prior sorting operations. Additionally, since d₂ is the median of the group, it has the same value as λ. It can be shown that both d₁ and d₂ are each less than or equal to the median of the nine values and, hence, can be removed from the nine values. Now label the three values having γ as its median in ascending order as f₁≦f₂≦f₃. Again, it is noted that f₂ has the same value as γ. It can be shown that the values f₂ and f₃ are each greater than or equal to the median of the nine values and, hence, can also be removed from the nine values. Thus, leaving five values including d₃, f₁ and a group of three values having β as its median that is labeled in ascending order as e₁≦e₂≦e₃. These remaining five values are divided into two groups and further sorted. One group includes d₃ and e₁ that after sorting via sorter 105 are labeled in ascending order as g₁≦g₂. This sorting requires only one comparison. The second group includes e₂, e₃ and f₁ that after sorting via sorter 106 are labeled in ascending order as h₁≦h₂≦h₃. This sorting only requires two comparisons because e₂ and e₃ have already been sorted. Of the remaining five values g₁, g₂, h₁, h₂ and h₃, it can be shown that value g₁ is less than or equal to the median of the nine values and can be removed, and that value h₃ is greater than or equal to the median of the nine values and can be removed, leaving values g₂, h₁ and h₂. These remaining three values are sorted via sorter 107 and labeled in ascending order as j₁≦j₂≦j₃. This sorting takes only two comparisons because values h₁ and h₂ have already been sorted. The median value of the group from sorter 107 is the median of the nine values and is value j₂. It is noted that in this process four values have been identified that are less than or equal to the median of the nine values, namely, d₁, d₂, g₁ and j₁. Similarly, four values have been identified that are greater than or equal to the median of the nine values, namely, f₂, f₃, h₃ and j₃.

[0028] It should be noted that if so-called pipelining is used in the median filter 110, only one three value sorter is required for sorters 101, 102, 103 and 104 because the prior sorted results are stored for use in the subsequent sortings.

[0029] As indicated above, d₁ and d₂ are each less than or equal to the median of the nine values and, hence, can be removed from the nine values. This can be done because d₂ (and hence d₁ which is less than d₂) is less than or equal to at least 5 of the 9 values (for which the median is desired). Consider the following: d₂≦d₃ (because they are sorted); d₂≦e₂≦e₃ (because d₂=λ, e₂=β and λ≦β, and e₁, e₂ and e₃ are sorted); and d₂≦f₂≦f₃ (because d₂=λ, f₂≦γ, λ≦β≦γ, and f₁, f₂ and f₃ are sorted). Consequently, d₂ is less than or equal to 5 values, namely, d₃, e₂, e₃, f₂ and f₃.

[0030] Recall that the median of the 9 values is the value that is greater than or equal to 4 values, and less than or equal to 4 other values. Since d₂ is less than or equal to 5 values, then either d₂ is not the median, in which case it can be removed, or d₂ is the median. However, if d₂ is the median, then d₂ must either be equal to d₃ or e₂, in which case d₃ or e₂ is also a median, consequently d₂ can be removed as well (note that our assertion is that the median is guaranteed to be in the surviving values). How is it known that if d₂ is the median, then d₂ must be equal to d₃ or e₂? The proof is as follows: if d₂ is equal to d₃ then proof done. Otherwise, d₂ must be less than d₃, i.e., d₂<d₃. In this case, d₂ must be equal to e₂. Because if otherwise, d₂ is not equal to e₂, then d₂<e₂≦e₃≦f₂≦f₃. That is, d₂ is strictly less than 5 values d₃, e₂, e₃, f₂, f₃. This shows that d₂ could not be the median. This contradiction shows that if d₂ is the median, then d₂ must be equal to either d₃ or e₂. Since d₁≦d₂, the same analysis shows that d₁ can be removed.

[0031] An analysis essentially identical to that above can be used to show that f₂ and f₃, and that g₁ and h₃ can be removed. The main difference is that “less than” is replaced by “greater than” in the above analysis.

[0032]FIG. 2 shows in simplified form a so-called pseudo 9-point spatial median filter. Referring to FIG. 2, it is seen that the 9-points, i.e., values, are arranged into three groups of three values each, namely, a first group including values a, b and c, a second group including values d, e and f, and a third group including values g, h and j. The first group is supplied to sorter 201, the second group to sorter 202 and the third group to sorter 203. Sorters 201, 202 and 203 each perform a complete sort of their respective supplied groups, i.e., arrange the supplied values in either ascending or descending order. In the spatial median filter shown in FIG. 2, it is assumed that the values are arranged in ascending order. That is, a₃≧a₂≧a₁ and so on for the other values. Note that a sort of three values requires three comparisons. Thus, the three sorters 201, 202 and 203 perform nine comparisons. The median of each group is determined to be the middle value in the sorted group. The three medians from sorters 201, 202 and 203, in this example, are a₂, b₂ and c₂, respectively, and are supplied to sorter 204. In turn, sorter 204 sorts the three medians a₂, b₂ and c₂. This requires another three comparisons. After sorting, the three medians a₂, b₂ and c₂, are assumed to be arranged in ascending order and are designated d₁, d₂ and d₃, where d₁≦d₂≦d₃. Take the median of them, namely, d₂, as the psuedo-median. Total number of comparisons is 12.

[0033] The above-described embodiments are, of course, merely illustrative of the principles of the invention. Indeed, numerous other methods or apparatus may be devised by those skilled in the art without departing from the spirit and scope of the invention. 

What is claimed is:
 1. A method of determining a median value of a plurality of values for use in a spatial median filter comprising the steps of: arranging said plurality of values into a prescribed number of groups of values; sorting the values in each group to arrange them in a prescribed order; determining the median value of each group of sorted values; and sorting the median values of the prescribed number of groups to determine the median of the plurality of values.
 2. The method as defined in claim 1 wherein said step of sorting said median values includes a step of arranging said sorted median values in a prescribed order.
 3. The method as defined in claim 2 wherein said prescribed number of groups is an odd number.
 4. The method as defined in claim 3 wherein said median value is a middle value of each group of the sorted values.
 5. The method as defined in claim 3 wherein said odd number is three (3).
 6. The method as defined in claim 5 wherein said number of values is at least nine (9).
 7. The method as defined in claim 2 wherein said step of sorting includes a step of selecting a prescribed one of said median values in said prescribed order as said median of said plurality of values.
 8. The method as defined in claim 1 wherein said step of sorting said median values includes steps of arranging said median values in a prescribed order, determining in a prescribed at least one of said groups a first sub-group of values less than or equal to the median of the group and determining in a prescribed at least one of said groups a second sub-group of values that are greater than or equal to the median value for each group, eliminating prescribed values in said sub-groups in accordance with prescribed criteria and eliminating prescribed one or more of said median values of said groups in accordance with prescribed criteria.
 9. The method as defined in claim 8 further including steps of determining the median of said median values, determining values remaining after said eliminating of values, arranging said remaining values including the median of said median values in a second prescribed number of groups and sorting said remaining values in each group of said second number of groups to arrange the remaining values in a prescribed order.
 10. The method as defined in claim 9 further including steps of eliminating prescribed ones of said ordered remaining values in accordance with prescribe criteria to obtain a set of values, sorting said set of values to arrange the values in said set in a prescribed order and selecting the median value of said ordered set of values as the median of said plurality of values.
 11. The method as defined in claim 10 wherein said prescribed number of groups is an odd number.
 12. The method as defined in claim 11 wherein said median value is a middle value of each group of the sorted values.
 13. The method as defined in claim 11 wherein said odd number is three (3).
 14. The method as defined in claim 13 wherein said number of values is at least nine (9).
 15. Apparatus for determining a median value of a plurality of values for use in a spatial median filter comprising: a first plurality of sorters, each for arranging a supplied group of values of said plurality of values in a prescribed order and for selecting a median value of said ordered values, said plurality of values being arranged into a prescribed number of groups of values and individual ones of said groups of values being supplied on a one-to-one basis to said first plurality of sorters; and at least one second sorter supplied with the median values of the prescribed number of groups for determining the median of the plurality of values.
 16. The apparatus as defined in claim 15 wherein said one at least one second sorter arranges said sorted median values in a prescribed order.
 17. The apparatus as defined in claim 16 wherein said prescribed number of groups is an odd number.
 18. The apparatus as defined in claim 17 wherein said median value is a middle value of each group of the sorted values.
 19. The apparatus as defined in claim 17 wherein said odd number is three (3).
 20. The apparatus as defined in claim 19 wherein said number of values is at least nine (9).
 21. The apparatus as defined in claim 16 wherein a prescribed one of said median values in said prescribed order from said at least one second sorter is said median of said plurality of values.
 22. The apparatus as defined in claim 15 wherein said at least one second sorter arranges said median values in a prescribed order, determines the median of said median values, determines in a prescribed at least one of said groups a first sub-group of values less than or equal to the median of the group and determines in a prescribed at least one of said groups a second sub-group of values that are greater than or equal to the median value for each group, said prescribed values in said sub-groups being eliminated in accordance with prescribed criteria and prescribed one or more of said median values of said groups being eliminated in accordance with prescribed criteria.
 23. The apparatus as defined in claim 22 further including a second plurality of sorters, supplied with values remaining after said eliminating of values in a second prescribed number of groups including said median of said median values and sorting said remaining values, each of said second groups being supplied to said second plurality of sorters on a group-by-group basis for arranging the remaining values in each of said second groups in a prescribed order.
 24. The apparatus as defined in claim 23 further including at least one third sorter supplied with said remaining values less prescribed ones of said ordered remaining values which have been eliminated in accordance with prescribe criteria to obtain a set of values, for sorting said set of values to arrange the values in said set in a prescribed order and selecting the median value of said ordered set of values as the median of said plurality of values.
 25. The apparatus as defined in claim 24 wherein said prescribed number of groups is an odd number.
 26. The apparatus as defined in claim 25 wherein said median value is a middle value of each group of the sorted values.
 27. The apparatus as defined in claim 25 wherein said odd number is three (3).
 28. The apparatus as defined in claim 27 wherein said number of values is at least nine (9). 